#
# print('The sum of 7 and 9 is [7 + 9].')
#
import re

sources = ['The sum of 7 and 9 is [7 + 9].']

field_pat = re.compile(r'\[(.+?)\]')
scope = {}


# 评估并计算
def replacement(match):
    code = match.group(1)
    try:
        print(code)
        return str(eval(code, scope))
    except SyntaxError:
        return ''


text = ' '.join(sources)

print(field_pat.sub(replacement, text))
# The sum of 7 and 9 is 16.
